package com.cetc.sdp.kmga.cs.jdbc;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.cetc.sdp.kmga.cs.util.Tool;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Druid 数据库连接池对象
 * 持有HBase和MySQL数据源
 * @description:
 * @author： DengQiang
 * @date: 2017/2/9 16:12
 */
public class DruidPool {

    private static DruidDataSource mysqlSource;

    private static DruidPool druidPool;

    private final static String MYSQL_PATH = "druid-mysql.properties";

    static {
        druidPool = new DruidPool();
        try {
            Properties mysqlProperties = Tool.loadProperties(MYSQL_PATH);
            mysqlSource = (DruidDataSource) DruidDataSourceFactory
                    .createDataSource(mysqlProperties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private DruidPool() {}

    public static DruidPool getInstance() {
        return druidPool;
    }

    public DruidDataSource getMysqlSource() {
        return mysqlSource;
    }

    public Connection getConnection() throws SQLException {
        return mysqlSource.getConnection();
    }
}
